<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <link rel="stylesheet" href="../styles/table-dark-theme.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <title>生产准备看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .header-title {
      font-size: 24px !important;
    }

    .el-form-item__label {
      color: #fff;
    }

    .el-table__header .el-table__cell {
      color: #1E9FFF !important;
    }

    .el-form-item {
      margin-bottom: 0px;
    }

    /* 工艺表格 */
    #gongyi .el-table .el-table__cell {
      padding: 5px 0px !important;
    }

    #tool .el-table .el-table__cell {
      padding: 5px 0px !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 5px;">
      <el-row>
        <el-col :span="6"><img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" /></el-col>
        <el-col :span="12" class="header-title">{{factoryname}}生产准备看板</el-col>
        <el-col :span="6" class="currentTime">{{currentTime}}</el-col>
      </el-row>

      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item label="分厂:">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择" @change="searchData">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>

      <!-- 第一行图表 -->
      <el-row>
        <el-col :span="12">
          <dv-border-box-11 title="分厂投料情况" ref="touLiaoBar">
            <div style="height: 310px;padding-top: 40px;" id="touLiaoBar"></div>
          </dv-border-box-11>
        </el-col>
        <el-col :span="12">
          <dv-border-box-11 title="工艺准备情况" ref="gongyi">
            <div id="gridWrapper" style="padding:60px 30px 0 30px;height:290px;">
              <div id="gongyi">
                <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
                  element-loading-background="rgba(0,0,0,0.8)" :data="gongYi.dataList" stripe border>
                  <el-table-column type="index" width="40"></el-table-column>
                  <el-table-column label="问题描述" prop="description" show-overflow-tooltip></el-table-column>
                  <el-table-column label="问题类型" prop="ufccontent" width="80" show-overflow-tooltip></el-table-column>
                  <el-table-column label="提出单位" prop="workcentername" width="100" show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column label="提交人" prop="submitperson" width="60"></el-table-column>
                  <el-table-column label="状态" prop="status" width="80"></el-table-column>
                  <el-table-column label="超期时间" prop="delayday" width="80" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <span v-if="scope.row.delayday> 0" style="color:red;">{{scope.row.delayday}}天</span>
                      <span v-else>{{scope.row.delayday}}</span>
                    </template>
                  </el-table-column>
                </el-table>

                <!-- 分页组件 -->
                <el-pagination @current-change="handleGongYiCurrentChange" :current-page="gongYi.queryInfo.currentPage"
                  :page-sizes="[gongYi.queryInfo.pageSize]" :page-size="gongYi.queryInfo.pageSize"
                  layout="prev,pager,next,jumper,sizes,total" :total="gongYi.total">
                </el-pagination>
              </div>
            </div>
          </dv-border-box-11>
        </el-col>
      </el-row>

      <!-- 工装工具准备情况 -->
      <dv-border-box-11 title="工装工具准备情况" ref="tool">
        <div id="tool" style="padding: 30px;padding-top:60px;padding-bottom:10px;height: 200px;">
          <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
            element-loading-background="rgba(0,0,0,0.8)" :data="tool.dataList" stripe border>
            <el-table-column type="index" width="40"></el-table-column>
            <el-table-column label="件号" prop="productname" width="120" show-overflow-tooltip></el-table-column>
            <el-table-column label="批次" prop="togetherflag" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column label="工序号" prop="sequence" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column label="工具编号" prop="toolno" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column label="工具名称" prop="toolname" show-overflow-tooltip></el-table-column>
            <el-table-column label="需求数量" prop="qty" width="80"></el-table-column>
            <el-table-column label="提出日期" prop="createdate" width="100" :formatter="splitDate"></el-table-column>
            <el-table-column label="需求日期" prop="needdate" width="100" :formatter="splitDate"></el-table-column>
            <el-table-column label="工区" prop="workcentername" width="80"></el-table-column>
            <el-table-column label="班组" prop="teamname" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column label="使用人" prop="fullname" width="80"></el-table-column>
            <el-table-column label="准备情况" prop="toolstatus" width="80"></el-table-column>
            <el-table-column label="超期时间" prop="delaydays" width="80">
              <template slot-scope="scope">
                <span v-if="scope.row.delaydays> 0" style="color:red;">{{scope.row.delaydays}}天</span>
                <span v-else>{{scope.row.delaydays}}</span>
              </template>
            </el-table-column>
          </el-table>

          <!-- 分页组件 -->
          <el-pagination @current-change="handleToolCurrentChange" :current-page="tool.queryInfo.currentPage"
            :page-sizes="[tool.queryInfo.pageSize]" :page-size="tool.queryInfo.pageSize"
            layout="prev,pager,next,jumper,sizes,total" :total="tool.total">
          </el-pagination>
        </div>
      </dv-border-box-11>

      <!-- 各工区工装准备情况 -->
      <dv-border-box-11 title="各工区工装准备情况" ref="workcenterBar">
        <div style="height: 250px;padding-top: 40px;" id="workcenterBar"></div>
      </dv-border-box-11>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { getFactory } from '../Scripts/hooks/fetchAPI.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    const app = new Vue({
      el: '#app',
      data: {
        splitDate,
        loading: false,
        loadingText: '数据加载中...',
        currentTime: '',
        queryInfo: { factoryid: '' },
        factoryname: '',
        factoryList: [],
        gongYi: {
          total: 0,
          dataList: [],
          queryInfo: {
            currentPage: 1,//当前页
            pageSize: 5//每页显示条数
          }
        },
        tool: {
          total: 0,
          dataList: [],
          queryInfo: {
            currentPage: 1,//当前页
            pageSize: 5//每页显示条数
          }
        },
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff', color: '#66b1ff' }
      },
      methods: {
        //投料情况
        async getTouliaoInfo() {
          echarts.dispose(document.getElementById("touLiaoBar"));
          let chart = echarts.init(document.getElementById('touLiaoBar'));
          chart.showLoading(this.loadingConfig);
          const { data: { data, meta, total } } = await axios.post('../handler/board/WorkPrepareDashBoard.ashx?action=getTouliaoInfo', {
            type: 'getTouliaoInfo',
            ...this.queryInfo
          })
          chart.hideLoading()
          if (meta.status === 500) {
            return this.$message.error(meta.msg)
          }
          echarts.dispose(document.getElementById("touLiaoBar"));
          chart = echarts.init(document.getElementById('touLiaoBar'));

          let arrWorkcenter = [], arrNotDaoliaoQty = [], arrDaoLiaoQty = [];
          data.forEach(i => {
            arrWorkcenter.push(i.workcentername);
            arrNotDaoliaoQty.push(i.notdaoliaoqty);
            arrDaoLiaoQty.push(i.daoliaoqty);
          });

          let option = barOption();
          option.legend.data = ['已到料', '未到料'];//设置图例文字
          option.xAxis.data = arrWorkcenter;
          option.yAxis[1].show = false;

          option.series[0] = _.merge(option.series[0], {
            name: '已到料', data: arrDaoLiaoQty,
            label: { color: colorList.green.color },
            itemStyle: { color: { colorStops: colorList.green.colorStops } }
          });

          option.series[1] = _.merge(_.cloneDeep(option.series[0]), {
            name: '未到料', data: arrNotDaoliaoQty,
            label: { color: colorList.red.color },
            itemStyle: { color: { colorStops: colorList.red.colorStops } }
          });

          chart.setOption(option);
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.touLiaoBar.initWH(); chart.resize(); }, 300);
        },
        //工艺准备
        async getGongYi() {
          this.loading = true
          this.loadingText = '数据加载中...'
          const { data: { data, meta, total } } = await axios.post('../handler/board/WorkPrepareDashBoard.ashx?action=getGongyiZhunBei', {
            type: 'getGongyiZhunBei',
            ...this.queryInfo,
            ...this.gongYi.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) {
            return this.$message.error(meta.msg)
          }
          this.gongYi.dataList = data;
          this.gongYi.total = total;
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.gongyi.initWH(); }, 300);
        },
        //工装工具
        async getTool() {
          this.loading = true
          this.loadingText = '数据加载中...'
          const { data: { data, meta, total } } = await axios.post('../handler/board/WorkPrepareDashBoard.ashx?action=getTool', {
            type: 'getTool',
            ...this.queryInfo,
            ...this.tool.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) {
            return this.$message.error(meta.msg)
          }
          this.tool.dataList = data;
          this.tool.total = total;
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.tool.initWH(); }, 300);
        },
        //各工区工装准备情况
        async getWorkcenterPrepare() {
          echarts.dispose(document.getElementById("workcenterBar"));
          let chart = echarts.init(document.getElementById('workcenterBar'));
          chart.showLoading(this.loadingConfig);
          const { data: { data, meta, total } } = await axios.post('../handler/board/WorkPrepareDashBoard.ashx?action=getWorkcenterPrepare', {
            type: 'getWorkcenterPrepare',
            ...this.queryInfo
          })
          chart.hideLoading()
          if (meta.status === 500) {
            return this.$message.error(meta.msg)
          }
          echarts.dispose(document.getElementById("workcenterBar"));
          chart = echarts.init(document.getElementById('workcenterBar'));
          let arrWorkcenter = [], arrDaiZhunBei = [], arrPeiSongZhong = [];
          data.forEach(i => {
            arrWorkcenter.push(i.workcentername);
            arrDaiZhunBei.push(i.daizhunbei);
            arrPeiSongZhong.push(i.peisongzhong);
          });

          let option = barOption();
          option.legend.data = ['待准备', '配送中'];//设置图例文字
          option.xAxis.data = arrWorkcenter;
          option.yAxis[1].show = false;

          option.series[0] = _.merge(option.series[0], {
            name: '待准备', data: arrDaiZhunBei,
            label: { color: colorList.red.color },
            itemStyle: { color: { colorStops: colorList.red.colorStops } }
          });

          option.series[1] = _.merge(_.cloneDeep(option.series[0]), {
            name: '配送中', data: arrPeiSongZhong,
            label: { color: colorList.green.color },
            itemStyle: { color: { colorStops: colorList.green.colorStops } }
          });

          chart.setOption(option);
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.workcenterBar.initWH(); chart.resize(); }, 300);
        },
        handleGongYiCurrentChange(newPage) {
          this.gongYi.queryInfo.currentPage = newPage;
          this.getGongYi();
        },
        handleToolCurrentChange(newPage) {
          this.tool.queryInfo.currentPage = newPage;
          this.getTool();
        },
        searchData() {
          this.factoryname = this.factoryList.filter(item => item.factoryid === this.queryInfo.factoryid)[0].factoryname;
          this.getTouliaoInfo();
          this.getGongYi();
          this.getTool();
          this.getWorkcenterPrepare();
        }
      },
      async mounted() {
        let incrementNumber = () => {
          setTimeout(incrementNumber, 500);
          this.currentTime = dayjs().format('YYYY年MM月DD日  HH:mm:ss');
        }
        setTimeout(incrementNumber, 500);
        this.factoryList = await getFactory();
        this.queryInfo.factoryid = this.factoryList[0].factoryid;
        this.factoryname = this.factoryList.filter(item => item.factoryid === this.queryInfo.factoryid)[0].factoryname;
        this.getTouliaoInfo();
        this.getGongYi();
        this.getTool();
        this.getWorkcenterPrepare();
      }
    })
  </script>
</body>

</html>